<?php
defined('SYSPATH') or die('No direct script access.');

class Model_Member extends Model_Base{
	
	protected $_table_name  = 'member';
	protected $_table_names_plural = false;
	
	public function insert($dataArray){
		$dataArray["createtime"] = Date::formatted_time();
		$dataArray["updatetime"] = Date::formatted_time();
		$dataArray["city"] = 1;
		if($this->values($dataArray)->check()){
			return $this->save();
		}
		return false;
	}
	
	public function update($dataArray){
		$dataArray = array_slice($dataArray, 1, sizeof($dataArray));//remove id
		$dataArray["updatetime"] = Date::formatted_time();
		if($this->values($dataArray)->check()){
			return $this->save();
		}
		return false;
	}
	
	protected function modelWithCondition($filters){
		$model = $this->where("status","=","A");
		if (array_key_exists("queryType", $filters)){
			$queryText = $this->convertToUtf8($filters["queryText"]);
			if ($filters["queryType"] == "number"){
				$model = $this->and_where_open()
				->where("phone","like","%".$queryText."%")
				->or_where("telephone","=","%".$queryText."%")
				->or_where("qq","=","%".$queryText."%")
				->and_where_close();
			}else{
				$model = $this->and_where($filters["queryType"],"like","%".$queryText."%");
			}
		}
		return $model->order_by("createtime","DESC");
	}
}